Node.js 8 the Right Way by Jim Wilson

Node.js 8 the Right Way by Jim Wilson

Author:Jim Wilson
Language: eng
Format: epub
Tags: Pragmatic Bookshelf
Publisher: Pragmatic Bookshelf


Now, continuing with the previous example, if the user only wanted to get back the title field of matching documents, then the thing to do is add -f title to the command line. request would then encode both options together as ?q=Mark%20Twain&_source=title.

After you save the file, give the new query command a try. The simplest query is the empty query, which matches all documents.

​ ​$ ​​./esclu​​ ​​q​​ ​​|​​ ​​jq​​ ​​'.'​​ ​​|​​ ​​head​​ ​​-n​​ ​​30​

​ {

​ "took": 4,

​ "timed_out": false,

​ "_shards": {

​ "total": 5,

​ "successful": 5,

​ "failed": 0

​ },

​ "hits": {

​ "total": 53212,

​ "max_score": 1,

​ "hits": [

​ {

​ "_index": "books",

​ "_type": "book",

​ "_id": "pg100",

​ "_score": 1,

​ "_source": {

​ "id": 100,

​ "title": "The Complete Works of William Shakespeare",

​ "authors": [

​ "Shakespeare, William"

​ ],

​ "subjects": [

​ "English drama -- Early modern and Elizabethan, 1500-1600"

​ ]

​ }

​ },

​ {

​ "_index": "books",

To abbreviate output, we can focus on just the title and author fields.

​ ​$ ​​./esclu​​ ​​q​​ ​​-f​​ ​​title,authors​​ ​​|​​ ​​jq​​ ​​'.'​​ ​​|​​ ​​head​​ ​​-n​​ ​​30​

​ {

​ "took": 5,

​ "timed_out": false,

​ "_shards": {

​ "total": 5,

​ "successful": 5,

​ "failed": 0

​ },

​ "hits": {

​ "total": 53212,

​ "max_score": 1,

​ "hits": [

​ {

​ "_index": "books",

​ "_type": "book",

​ "_id": "pg100",

​ "_score": 1,

​ "_source": {

​ "title": "The Complete Works of William Shakespeare",

​ "authors": [

​ "Shakespeare, William"

​ ]

​ }

​ },

​ {

​ "_index": "books",

​ "_type": "book",

​ "_id": "pg1000",

​ "_score": 1,

​ "_source": {

Now using jq we can focus on just the source objects.

​ ​$ ​​./esclu​​ ​​q​​ ​​-f​​ ​​title,authors​​ ​​|​​ ​​jq​​ ​​'.hits.hits[]._source'​​ ​​|​​ ​​head​​ ​​-n​​ ​​30​

​ {

​ "title": "The Complete Works of William Shakespeare",

​ "authors": [

​ "Shakespeare, William"

​ ]

​ }

​ {

​ "title": "La Divina Commedia di Dante: Complete",

​ "authors": [

​ "Dante Alighieri"

​ ]

​ }

​ {

​ "title": "The Magna Carta",

​ "authors": [

​ "Anonymous"

​ ]

​ }

​ {

​ "title": "My First Years as a Frenchwoman, 1876-1879",

​ "authors": [

​ "Waddington, Mary King"

​ ]

​ }

​ {

​ "title": "A Voyage to the Moon\r\nWith Some Account of the Manners and ...

​ "authors": [

​ "Tucker, George"

​ ]

​ }

Taking advantage of the joining of query parts, you can specify a complex query without wrapping it in quotes.

​ ​$ ​​./esclu​​ ​​q​​ ​​authors:Shakespeare​​ ​​AND​​ ​​subjects:Drama​​ ​​-f​​ ​​title​​ ​​|\​

​ ​jq​​ ​​'.hits.hits[]._source.title'​

​ "The Tragedy of Othello, Moor of Venice"

​ "The Tragedy of Romeo and Juliet"

​ "The Tempest"

​ "The Comedy of Errors"

​ "Othello"

​ "As You Like It"

​ "The Two Gentlemen of Verona"

​ "The Merchant of Venice"

​ "Two Gentlemen of Verona"

​ "All's Well That Ends Well"

Be aware that if you need any characters that your shell treats as special, you should wrap the whole query in quotes. For example, to do a multiword query with Elasticsearch you can wrap the expression in double quotes (q title:"United States"). But your shell may strip out these quotes unless they’re wrapped in another set of quotes (q ’title:"United States"’).



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.